package top.shen33.yang.controller;

import org.springframework.web.multipart.MultipartFile;
import top.shen33.yang.base.R;
import top.shen33.yang.model.entity.RbacPermission;
import top.shen33.yang.services.RbacPermissionService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author oreilly
 * @since 2018-08-23
 */
@RestController
@RequestMapping("/rbacPermission")
public class RbacPermissionController extends BaseController<RbacPermission> {


            @Autowired
            private RbacPermissionService rbacPermissionService;




            @Override
            public Object doAdd(@RequestBody RbacPermission rbacPermission) throws Exception {

                    rbacPermissionService.doAdd(rbacPermission);
                    return R.ok(rbacPermission);
            }

            @Override
            public Object deDelete(String[] ids) throws Exception {

                    rbacPermissionService.doDelete(ids);
                    return R.ok("delete ok");
            }

            @Override
            public Object doUpdate(@RequestBody RbacPermission rbacPermission) throws Exception {

                    rbacPermissionService.doUpdate(rbacPermission);
                    return R.ok(rbacPermission);
            }

            @Override
            public Object getOne(@PathVariable String id) throws Exception {
                    RbacPermission rbacPermission = rbacPermissionService.getOne(id);
                    return R.ok(rbacPermission);
            }


            public Object all(RbacPermission rbacPermission) throws Exception{
                    List<RbacPermission> rbacPermissionList = rbacPermissionService.all(rbacPermission);
                    return R.ok(rbacPermissionList);
            }

    @Override
    public void exportExcel(HttpServletResponse response, RbacPermission rbacPermission) throws Exception {

    }

    @Override
    public Object importExcel(MultipartFile file) throws Exception {
        return null;
    }

    @Override
            public Object pageInfo(Page page, RbacPermission rbacPermission) throws Exception {

                    Page<RbacPermission> rbacPermissionPage = rbacPermissionService.pageInfo(page, rbacPermission);
                    return R.ok("page",rbacPermissionPage);
            }


            @RequestMapping("/tree")
        public Object tree() throws Exception{
                RbacPermission tree = rbacPermissionService.tree();
                return R.ok(tree);
        }


}

